﻿
let ros = [];

export function regCallback(rowElement, csThis) {
    if (rowElement == null)
        return;
    rowElement.ext = {};
    rowElement.ext.csMouseLeaveFunc = (event) => {
        csThis.invokeMethodAsync('MouseLeave');
    };
    rowElement.addEventListener('mouseleave', rowElement.ext.csMouseLeaveFunc);

    let elems = rowElement.querySelectorAll('.th-width-dependent');
    if (elems) {
        for (let i = 0; i < elems.length; i++) {
            let elem = elems[i];
            let tableElem = elem.closest('table');
            //console.log('tableElem', tableElem);
            let theadElem = tableElem.tHead;
            //console.log('theadElem', theadElem);
            let thWidthDriveElem = theadElem.querySelectorAll('th')[elem.cellIndex]
                .querySelector('.th-width-drive');
            let ro = new ResizeObserver((entries, observer) => {
                elem.style.maxWidth = thWidthDriveElem.style.width;
            });
            ro.observe(elem);
            ros.push(ro);
        }
    }
}
export function unregCallback(rowElement) {
    if (rowElement)
        rowElement.removeEventListener('mouseleave', rowElement.ext.csMouseLeaveFunc);
    for (let ro of ros)
        ro.disconnect();
}